const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const baseWebpackConfig = require('./webpack.config.base');
const glob = require('glob');
const ManifestPlugin = require('webpack-assets-manifest');
const {project,version} =require('../build/project');
function resolve (dir) {
    return path.join(__dirname, '..', dir);
}
let index = process.argv.findIndex((item) => {
    return item === '--port';
});
console.log('====process.argv====', process.argv[index + 1]);
const port = process.argv[index + 1] || 8080;
module.exports = merge(baseWebpackConfig, {
    entry: {
        index: [
            //热加载
            'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=10000&reload=true',
        ]
    },
    output: {
        publicPath: '/',
        path: resolve('../dist/'+project+ '/'+version),
        filename: 'static/[name]-'+version+'.js?ver='+version,
        chunkFilename: 'static/routes/[name]-'+version+'.chunk.js?version='+version, // 按需加载输出的文件名
    },
    mode: 'development',
    resolve: {
        extensions: ['.web.js', '.js', '.jsx', '.json', '.less', '.css'],
        alias: {
            'env': resolve('../src/config/env/development'),
        }
    },
    // cheap-module-eval-source-map is faster for development
    devtool: '#cheap-module-eval-source-map',
    devServer: {
        contentBase: './',
        hot: true,
        port: port,
        // compress:true,

        //解决跨域
        proxy: {
        
        },

    },
    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new ManifestPlugin(path.join(__dirname, './'), 'manifest.json')
    ]
}
);
